<script setup>
import router from "../../../router/index.js";
import MyNav from "../../../components/MyNav.vue";
import MyForm from "../../../components/MyForm.vue";
import {RULE} from "../../../const/index.js";
import {reactive, ref} from "vue";
import {insertApi} from "../../../api/axios.js";
import {SECKILL_STATUS_OPTIONS} from "../../../const/project.js";

/* ==================== 页面常量 ==================== */

// 路径导航
const navItems = [
  {icon: 'Goods', label: '营销管理'},
  {icon: 'Stopwatch', label: '秒杀列表', url: '/Seckill'},
  {icon: 'Plus', label: '添加秒杀'},
];

/* ==================== 添加表单 ==================== */

// 表单项 + 表单值 + 表单规则
let items = ref([
  {label: '活动标题', prop: 'title', required: true, span: 12},
  {
    label: '活动状态', prop: 'status', span: 12, type: 'select', required: true,
    options: SECKILL_STATUS_OPTIONS, placeholder: '请选择活动状态'
  },
  {label: '开始时间', prop: 'startTime', type: 'datetime', required: true, span: 12},
  {label: '结束时间', prop: 'endTime', type: 'datetime', required: true, span: 12},
  {label: '活动描述', prop: 'info', required: true, type: 'textarea'},
]);
let data = reactive({info: '暂无描述'});
let rules = {info: RULE.INFO};

/**
 * 添加成功后调用
 *
 * 1. 路由到 Seckill 页面
 */
function insertSuccess() {
  router.push('/Seckill');
}

</script>

<template>
  <my-nav :items="navItems"/>
  <el-divider/>
  <el-card class="seckill-insert-card" header="添加秒杀">
    <my-form type="insert"
             :args="{module: 'seckill'}"
             :items="items"
             :rules="rules"
             :api="insertApi"
             :params="data"
             :callback="insertSuccess"/>
  </el-card>
</template>

<style scoped lang="scss">
.seckill-insert-card {
  width: 70%; // 宽度
  margin: 20px auto 0; // 外边距
}
</style>